import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


def my_wait(met, path, driver):
    ele = WebDriverWait(driver, 10, 0.5).until(EC.presence_of_element_located((met, path)))
    return ele

driver = webdriver.Chrome()
driver.maximize_window()

driver.get("https://www.baidu.com")
# ele = driver.find_element(By.XPATH, "//span[text()='设置']")
# ActionChains(driver).move_to_element(ele).perform()
# # 显示等待
# # s_ele = WebDriverWait(driver, 10, 0.5).until(EC.presence_of_element_located((By.XPATH, "//span[text()='搜索设置']")))
# s_ele = my_wait(By.XPATH, "//span[text()='搜索设置']", driver)
# s_ele.click()
# sava_ele = my_wait(By.XPATH, "//a[text()='保存设置']", driver)
# sava_ele.click()
# driver.switch_to.alert.accept()

# 隐式等待
driver.implicitly_wait(10)
driver.find_element(By.XPATH, "//span[text()='搜索设置']").click()
driver.find_element(By.XPATH, "//a[text()='保存设置']").click()


time.sleep(5)
driver.quit()